MAZE ALGORITHM ============== Every room has a number Start in Room 1 Exit in Room N (max room number) CurrentRoom = 1 VisitedRooms = new Set() // all rooms that we've visited VisitedRoom.add(1) Path = new Stack() // path followed to reach CurrentRoom While (CurrentRoom != N) NextRoom = Any room reachable from CurrentRoom that's not in VisitedRooms If NextRoom >= 1 // Move forward Path.push(CurrentRoom) VisitedRooms.add(NextRoom) CurrentRoom = NextRoom Else // Backtrack CurrentRoom = Path.pop() Path.push(CurrentRoom) // same as Path.push(N) Solution = new Stack(); while (!Path.isEmpty()) Solution.push(Path.pop())